package design.patterns.pc;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

public class Producer implements  Runnable{

    private BlockingQueue queue;
    public  Producer(BlockingQueue queue){
        this.queue = queue;

    }

    @Override
    public void run() {
        while(true){
            Double data = Math.random()*100000;
            try {
                queue.put(data);
                System.out.println("生产者线程{"+Thread.currentThread().getName()+"}生产了数据:"+data);
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
